﻿' ******************************************************************************
' ** 
' **  Yahoo! Managed
' **  Written by Marius Häusler 2011
' **  It would be pleasant, if you contact me when you are using this code.
' **  Contact: YahooFinanceManaged@gmail.com
' **  Project Home: http://code.google.com/p/yahoo-finance-managed/
' **  
' ******************************************************************************
' **  
' **  Copyright 2011 Marius Häusler
' **  
' **  Licensed under the Apache License, Version 2.0 (the "License");
' **  you may not use this file except in compliance with the License.
' **  You may obtain a copy of the License at
' **  
' **    http://www.apache.org/licenses/LICENSE-2.0
' **  
' **  Unless required by applicable law or agreed to in writing, software
' **  distributed under the License is distributed on an "AS IS" BASIS,
' **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' **  See the License for the specific language governing permissions and
' **  limitations under the License.
' ** 
' ******************************************************************************


Namespace YahooManaged.RSS

    ''' <summary>
    ''' Provides RSS feed data.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Feed
        Private ReadOnly mHelper As New MyHelper

        Private mInputBox As TextInputBox

        ''' <summary>
        ''' Specify one or more categories that the channel belongs to.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Category() As Category
        ''' <summary>
        ''' Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Cloud() As Cloud
        ''' <summary>
        ''' Copyright notice for content in the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Copyright() As String
        ''' <summary>
        ''' 	Phrase or sentence describing the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description() As String
        ''' <summary>
        ''' A URL that points to the documentation (http://www.rssboard.org/rss-specification) for the format used in the RSS file. It's probably a pointer to this page. It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Documentation() As Uri
        ''' <summary>
        ''' A string indicating the program used to generate the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Generator() As String
        ''' <summary>
        ''' Specifies a GIF, JPEG or PNG image that can be displayed with the channel. 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Image() As Image
        ''' <summary>
        ''' A channel may contain any number of items. An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Items() As List(Of FeedItem)
        ''' <summary>
        ''' The language the channel is written in. This allows aggregators to group all Italian language sites, for example, on a single page.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Language() As Globalization.CultureInfo
        ''' <summary>
        ''' The last time the content of the channel changed.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastBuildDate() As DateTime
        ''' <summary>
        ''' The URL to the HTML website corresponding to the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Link() As Uri
        ''' <summary>
        ''' Email address for person responsible for editorial content.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ManagingEditor() As Mail.MailAddress
        Public Property Name() As String
        ''' <summary>
        ''' The publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That's when the pubDate of the channel changes.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PublishDate() As DateTime
        ''' <summary>
        ''' The PICS (http://www.w3.org/PICS/) rating for the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Rating() As String
        ''' <summary>
        ''' A hint for aggregators telling them which hours they can skip. This element contains up to 24 hour sub-elements whose value is a number between 0 and 23, representing a time in GMT, when aggregators, if they support the feature, may not read the channel on hours listed in the SkipHours element. The hour beginning at midnight is hour zero.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Skiphours() As Integer()
        ''' <summary>
        ''' A hint for aggregators telling them which days they can skip. This element contains up to seven day sub-elements whose value is Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. Aggregators may not read the channel during days listed in the SkipDays element.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Skipdays() As DayOfWeek()
        ''' <summary>
        ''' Specifies a text input box that can be displayed with the channel. The purpose of the TextInput element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property TextInput() As TextInputBox
        ''' <summary>
        ''' The name of the channel. It's how people refer to your service. If you have an HTML website that contains the same information as your RSS file, the title of your channel should be the same as the title of your website.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
        ''' <summary>
        ''' ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Ttl() As Integer
        ''' <summary>
        ''' Email address for person responsible for technical issues relating to channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Webmaster() As Mail.MailAddress

        Public Sub New()
            Me.Clear()
        End Sub

        Public Sub Clear()
            Me.Description = String.Empty
            Me.Title = String.Empty
            Me.Language = Nothing
            Me.Documentation = Nothing
            Me.PublishDate = #12:00:00 AM#
            Me.Copyright = String.Empty
            Me.Webmaster = Nothing
            Me.LastBuildDate = #12:00:00 AM#
            Me.Generator = String.Empty
            Me.Rating = String.Empty
            Me.ManagingEditor = Nothing
            Me.Link = Nothing
            Me.Name = String.Empty
            Me.Skipdays = New DayOfWeek() {}
            Me.Skiphours = New Integer() {}
            Me.Items = New List(Of FeedItem)
            Me.Image = Nothing
            Me.Category = Nothing
        End Sub
        Public Sub CopyValues(ByVal original As Feed)
            With Me
                If original.Category IsNot Nothing Then
                    .Category = New Category
                    .Category.Domain = original.Category.Domain
                    .Category.Name = original.Category.Name
                Else
                    .Category = Nothing
                End If
                .Description = original.Description
                .Copyright = original.Copyright
                .Documentation = original.Documentation
                .Generator = original.Generator
                If original.Image IsNot Nothing Then
                    .Image = New Image
                    .Image.Description = original.Image.Description
                    .Image.Height = original.Image.Height
                    .Image.Link = original.Image.Link
                    .Image.Title = original.Image.Title
                    .Image.URL = original.Image.URL
                    .Image.Width = original.Image.Width
                Else
                    .Image = Nothing
                End If
                If original.Items IsNot Nothing Then
                    .Items = New List(Of FeedItem)
                    For Each item As FeedItem In original.Items
                        Dim newItem As New FeedItem
                        newItem.CopyValues(item)
                        .Items.Add(newItem)
                    Next
                Else
                    .Items = Nothing
                End If
                .Language = original.Language
                .LastBuildDate = original.LastBuildDate
                .Link = original.Link
                .ManagingEditor = original.ManagingEditor
                .Name = original.Name
                .PublishDate = original.PublishDate
                .Rating = original.Rating
                .Skipdays = mHelper.EnumToArray(original.Skipdays)
                .Skiphours = mHelper.EnumToArray(original.Skiphours)
                .Title = original.Title
                .Ttl = original.Ttl
                .Webmaster = original.Webmaster
            End With
        End Sub
        Public Overrides Function ToString() As String
            Return Me.Title
        End Function
    End Class




    ''' <summary>
    ''' Stores data of a rss feed item.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class FeedItem

        ''' <summary>
        ''' The title of the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
        ''' <summary>
        ''' The URL of the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Link() As Uri
        ''' <summary>
        ''' The item synopsis.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description() As String
        ''' <summary>
        ''' Email address of the author of the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Author() As String
        ''' <summary>
        ''' Includes the item in one or more categories.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Category() As Category
        ''' <summary>
        ''' URL of a page for comments relating to the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Comments() As Uri
        ''' <summary>
        ''' Describes a media object that is attached to the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Enclosure() As Enclosure
        ''' <summary>
        ''' A string that uniquely identifies the item.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property GUID() As GUID
        Public Property InsertDate() As Date
        ''' <summary>
        ''' Indicates when the item was published.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PublishDate() As Date
        ''' <summary>
        ''' The RSS channel that the item came from.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Source() As Source

        Public Sub New()
            Me.Clear()
        End Sub

        Public Overridable Sub Clear()
            Me.Title = String.Empty
            Me.Link = Nothing
            Me.Description = String.Empty
            Me.Author = String.Empty
            Me.InsertDate = #12:00:00 AM#
            Me.PublishDate = #12:00:00 AM#
            Me.Comments = Nothing
            Me.GUID = Nothing
            Me.Category = Nothing
            Me.Enclosure = Nothing
            Me.Source = Nothing
        End Sub
        Public Overridable Sub CopyValues(ByVal n As FeedItem)
            With Me
                .Author = n.Author
                If n.Category IsNot Nothing Then
                    .Category = New Category
                    .Category.Domain = n.Category.Domain
                    .Category.Name = n.Category.Name
                Else
                    .Category = Nothing
                End If
                .Comments = n.Comments
                .Description = n.Description
                If n.Enclosure IsNot Nothing Then
                    .Enclosure = New Enclosure
                    .Enclosure.Length = n.Enclosure.Length
                    .Enclosure.Type = n.Enclosure.Type
                    .Enclosure.Url = n.Enclosure.Url
                Else
                    .Enclosure = Nothing
                End If
                .GUID = n.GUID
                .InsertDate = n.InsertDate
                .Link = n.Link
                .PublishDate = n.PublishDate
                .Source = n.Source
                .Title = n.Title
            End With
        End Sub

        Public Overrides Function ToString() As String
            Return Me.Title
        End Function
    End Class



    ''' <summary>
    ''' Provides information about a globally unique identifier. 
    ''' </summary>
    ''' <remarks></remarks>
    Public Class GUID
        ''' <summary>
        ''' It's a string that uniquely identifies the item. When present, an aggregator may choose to use this string to determine if an item is new.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>There are no rules for the syntax of a guid. Aggregators must view them as a string. It's up to the source of the feed to establish the uniqueness of the string.</remarks>
        Public Property ID() As String
        ''' <summary>
        '''  If the GUID element has an attribute named isPermaLink with a value of true, the reader may assume that it is a permalink to the item, that is, a url that can be opened in a Web browser, that points to the full item described by the FeedItem element.
        ''' </summary>
        ''' <value>If its value is FALSE, the guid may not be assumed to be a url, or a url to anything in particular.</value>
        ''' <returns></returns>
        ''' <remarks>IsPermaLink is optional, its default value is TRUE.</remarks>
        Public Property IsPermaLink() As Boolean
        Public Sub New()
            Me.ID = String.Empty
            Me.IsPermaLink = True
        End Sub
        Public Overrides Function ToString() As String
            Return Me.ID
        End Function
    End Class



    ''' <summary>
    ''' Enclosure describes a media object that is attached to the item. 
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Enclosure
        ''' <summary>
        ''' The location of the object.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Url() As Uri
        ''' <summary>
        ''' The MIME type of the object.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Type() As String
        ''' <summary>
        ''' The size in Bytes of the object.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Length() As Long
        Public Sub New()
            Me.Url = Nothing
            Me.Type = String.Empty
            Me.Length = 0
        End Sub
        Public Overrides Function ToString() As String
            Return Me.Type
        End Function
    End Class



    ''' <summary>
    ''' Provides information about the RSS channel where the item comes from.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Source
        ''' <summary>
        ''' The title of the RSS channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
        ''' <summary>
        ''' The url of the RSS channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Url() As Uri
        Public Sub New()
            Me.Url = Nothing
            Me.Title = String.Empty
        End Sub
        Public Overrides Function ToString() As String
            Return Me.Title
        End Function
    End Class



    ''' <summary>
    ''' Provides information about catigorization of the item.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Category
        ''' <summary>
        ''' The name of the category.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Name() As String
        Public Property Domain() As Uri
        Public Sub New()
            Me.Name = String.Empty
            Me.Domain = Nothing
        End Sub
        Public Overrides Function ToString() As String
            Return Me.Name
        End Function
    End Class




    ''' <summary>
    ''' Provides RSS feed image data.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Image
        ''' <summary>
        ''' Gets or sets the URL of a GIF, JPEG or PNG image that represents the channel.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property URL() As Uri
        ''' <summary>
        ''' Gets or sets the URL of the site, when the channel is rendered, the image is a link to the site.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>In practice the image TITLE and LINK should have the same value as the channel's TITLE and LINK.</remarks>
        Public Property Link() As Uri
        Public Property Title() As String
        ''' <summary>
        ''' Gets or sets the text that is included in the TITLE attribute of the link formed around the image in the HTML rendering.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description() As String
        ''' <summary>
        ''' Gets or sets the width of the image in pixels.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>Maximum value is 144, default value is 88.</remarks>
        Public Property Width() As Integer
        ''' <summary>
        ''' Gets or sets the height of the image in pixels.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>Maximum value is 400, default value is 31.</remarks>
        Public Property Height() As Integer
    End Class



    ''' <summary>
    ''' It's purpose is to allow processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Cloud
        Public Property Domain() As Uri
        Public Property Path() As String
        Public Property RegisterProcedure() As String
        Public Property Protocol() As String
        Public Property Port() As Integer
    End Class



    ''' <summary>
    ''' Represents a text input box for doing something.
    ''' </summary>
    ''' <remarks>The purpose of the TextInputBox element is something of a mystery. You can use it to specify a search engine box. Or to allow a reader to provide feedback. Most aggregators ignore it.</remarks>
    Public Class TextInputBox
        ''' <summary>
        ''' The label of the Submit button in the text input area.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
        ''' <summary>
        ''' Explains the text input area.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Description() As String
        ''' <summary>
        ''' The name of the text object in the text input area.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Name() As String
        ''' <summary>
        ''' The URL of the CGI script that processes text input requests.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Link() As Uri
    End Class



End Namespace
